package com.design.builderchaiun;

public abstract class Handler<T> {


    protected Handler chain;

    public void next(Handler handler) {
        this.chain = handler;
    }

    public abstract void doHandle(Member member);

    /**
     * 单向链
     * 从头部开始执行到尾部
     *
     *
     * @param <T>
     */
    public static class Builder<T> {

        private Handler<T> head;

        private Handler<T> tail;

        public Builder<T> addHandler(Handler<T> handler) {
            // 第一次进来头部是null 因此先对头部进行初始化
            if (this.head == null) {
                //
                this.head = this.tail = handler;
                return this;
            }
            // 第二次进来
            this.tail.next(handler);
            this.tail = handler;
            return this;
        }

        public Handler<T> build() {
            return this.head;
        }
    }
}
